﻿var page = 1;
var plen = 20;
$(function () {
    load_data();
});
function htmls(d) {
    $('#datas').append('<section class="aui-card-content"><div class="aui-card-media"><div class="aui-card-media-item"><img src="' + d.pic + '" onclick="location.href=\'/shop/product_dtl?code=' + d.pcode + '\';" /></div><div class="aui-card-media-inner"><div class="aui-card-media-text" onclick="location.href=\'/shop/product_dtl?code=' + d.pcode + '\';"><p>' + d.name + ' ' + d.subname + '</p></div><div class="aui-card-media-describe" style="margin-top:5px;"><div class="aui-list-title-btn" style="text-align:left;"><span>[' + (d.good == 1 ? '好评' : '差评') + '] ' + d.mname + '：' + d.content + '<br>' + (d.isreply == 1 ? ('回复：' + d.reply) : ('<div class="aui-list-title-btn"><a href="javascript:;" onclick="reply(\'' + d.code + '\')" class="red-color">回复评价</a></div>')) + '</span></div></div></div></div></section><div class="aui-dri"></div>');
}
function reply(code) {
    layer.open({
        title: false,
        content: '<div><textarea style="width:96%;height:80px;padding:2%;" id="content"></textarea></div><div style="margin-top:30px;"><button type="button" style="width:120px;background:#3F75FF;height:26px;border:none;color:#fff;border-radius:8px;font-size:14px;" onclick="save(\'' + code + '\')">提交回复</button></div>'
    });
}
function save(code) {
    var c = $('#content').val();
    layer.closeAll();
    loading();
    $.post('/dos_m/save_comment_reply', { code: code, content: c }, function (d) { eval(d); });
}
function ok() {
    layer.closeAll();
    txttip('处理成功', function () { location.href = location.href; });
}
function load_data() {
    $('#datas li').last().remove();
    $('#datas').append('<li style="padding:10px;text-align:center;">正在加载数据</li>');
    $.post('/dos_m/load_my_sale_comment', { page: page, plen: plen }, function (d) { eval(d); });
}
function next() {
    page++;
    load_data();
}
function show(d, p) {
    $('#datas li').last().remove();
    if (d.length == 0) {
        $('#datas').append('<li style="padding:10px;text-align:center;">没有数据了</li>');
        return;
    }
    page = p;
    for (var i = 0; i < d.length; i++) {
        $('#datas').append(
                htmls(d[i])
            );
    }
    $('#datas').append('<li style="padding:10px;text-align:center;" onclick="next()">点此加载更多</li>');
}
function err() {
    layer.closeAll();
    txttip('您尚未添加店铺，请先去添加店铺');
}